package com.feng.show.controller;


import com.feng.show.comm.ResponseCode;
import com.feng.show.comm.ServerResponse;
import com.feng.show.entity.UserInfo;
import com.feng.show.service.IUserInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/user")
public class UserInfoController {

    @Autowired
    IUserInfoService userInfoService;


    @PostMapping("/getAll")
    public ServerResponse<List<UserInfo>> getProductTypeList(

            @RequestParam(value = "userId") String userId) {

        userId = "10001";
        if (userId == null) {
            return ServerResponse.createByErrorCodeMessage(ResponseCode.ERROR.getCode(), "参数错误");

        } else {
            return userInfoService.getAllUerInfo(userId);
        }
    }

    /*
    添加用户
     */

    @PostMapping("/Add")
    public ServerResponse<Boolean> AddUser(

            @RequestParam(value = "userId") String userId,
            @RequestParam(value = "name") String name,
            @RequestParam(value = "pwd") String pwd,
            @RequestParam(value = "mobile") String moble,
            @RequestParam(value = "type") Integer type) {

        userId = "10001";

        if(name==null||name.length()<3){
            return ServerResponse.createBySuccessMsg("用户名不能小于3位");
        }
        if(pwd==null||pwd.length()<3){
            return ServerResponse.createBySuccessMsg("密码不能小于3位");
        }
        if(moble==null||moble.length()>11){
            return ServerResponse.createBySuccessMsg("手机号码输入错误");
        }

        return userInfoService.addUser(name,pwd,moble,type);

    }


    @PostMapping("/del")
    public ServerResponse<Boolean> delUser(

            @RequestParam(value = "userId") String userId,
            @RequestParam(value = "id") Integer id) {

        userId = "10001";

        if(id==null||id<1){
            return ServerResponse.createBySuccessMsg("参数错误");
        }


        return userInfoService.delUser(id);

    }


}
